from model.models import User
from schema.schema import UserSchema
from service.baseservice import BaseService
from etx import db


class UserService(BaseService):

    @classmethod
    def get_all_user(cls):
        users = User.query.all()
        user_list = UserSchema().dump(users, many=True)
        res = {
            'userList': user_list,
            'count': len(user_list)
        }
        return res

    @classmethod
    @BaseService.transactional
    def add_user(cls, user):
        user = UserSchema().load(user)
        user1 = User(username='小黑', sex='男', email='xiaohei@qq.com', password='123456grre')
        db.session.add_all([user, user1])
